<!--
 * @Date: 2025-04-24 09:41:49
 * @LastEditors: Csir 2215995096@qq.com
 * @LastEditTime: 2025-04-25 10:54:51
 * @FilePath: \infomng-ui\src\views\workorder\factoryLargeScreen\components\workShop.vue
-->
<template>
  <div>
    <el-select
      v-model="workShop"
      style="width: 150px"
      clearable
      :multiple="multiple"
      collapse-tags
      placeholder="请选择车间"
      @change="changeWorkShop"
    >
      <el-option
        v-for="item in workShopOpts"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      >
      </el-option>
    </el-select>
  </div>
</template>
<script>
import { workshop } from "@/api/common.js";
export default {
  data() {
    return {
      workShop: this.multiple?[]:"",
      workShopOpts: [],
    };
  },
  watch: {
    workShop: {
      handler(newVal) {
        this.$emit("change", newVal);
      },
      immediate: true,
    },
  },
  props:{
    multiple:{
      type:Boolean
    }
  },
  mounted() {
    this.getWorkshop();
  },
  methods: {
    changeWorkShop(val) {
      this.workShop = val;
    },
    async getWorkshop() {
      const res = await workshop();
      if (res) {
        this.workShopOpts = res.data.data.records.map((item) => {
          return {
            value: item.id,
            label: item.workshopName,
          };
        });
        this.workShop = this.multiple?[this.workShopOpts[0].value]:this.workShopOpts[0].value;
      }
    },
  },
};
</script>

<style lang="less" scoped></style>
